/*
 * @author Javier A. Ramírez M.
 * jaramirez85@yahoo.es
 */
package com.jav;

import com.jav.per.PersisSetup;
import com.sun.lwuit.Button;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;

public class Menu extends Form {

    private static final VentanaEspera waiting = new VentanaEspera("CARGANDO...");
    private static Form selector;

    public Menu() {
        super("...*INVMOVIL*...");


        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        Button btSistema = createButton("CARGUE ARCHIVOS", 1);
        addComponent(btSistema);

        Button btProductos = createButton("PRODUCTOS", 4);
        addComponent(btProductos);

        Button btClientes = createButton("CAPTURA", 2);
        addComponent(btClientes);

        Button btPedido = createButton("EXPORTAR", 3);
        addComponent(btPedido);

        PersisSetup pd = Datos.getInstance().getPersisSetup();
        if (pd != null && pd.PermisoInforme()) {
            Button btReporte = createButton("INFORMES", 5);
            addComponent(btReporte);
        }


    }

    private Button createButton(String name, int accion) {
        Button b = new Button(name);
        b.setAlignment(CENTER);
        b.addActionListener(new AccionForma(accion));
        return b;
    }

    class AccionForma implements ActionListener {

        private int selforma;

        public AccionForma(int forma) {
            this.selforma = forma;
        }

        public void actionPerformed(ActionEvent evt) {

            new Thread(new Runnable() {

                public void run() {
                    waiting.showModeless();
                    switch (selforma) {
                        case 1:
                            selector = new CarArchivos();
                            break;
                        case 3:
                            selector = new ExportForm();
                            break;
                        case 2:
                            selector = new CapturaForm();
                            break;
                        case 4:
                            selector = new ProductosForm();
                            break;
                        case 5:
                            selector = new ReportForm();
                            break;
                        case 6:
                            selector = new SetupForm();
                            break;

                    }
                    waiting.dispose();
                    selector.show();

                }
            }).start();
        }
    }
}
